package com.byxy.util;

public class TypeConverter {

    public static String toString(int[] data) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < data.length; i++) {
            sb.append((data[i] + "").trim()).append(",");
        }
        String newStr = sb.toString();
        return newStr.substring(0, newStr.length() - 1);
    }

    public static int[] toIntArray(String[] data) {
        int[] target = new int[data.length];
        for (int i = 0; i < data.length; i++) {
            target[i] = Integer.parseInt(data[i]);
        }
        return target;
    }

    public static int[] toIntArray(String data) {
        if (data == null || data.trim().length() == 0) {
            return new int[0];
        }
        String[] items = data.split(",");
        int[] target = new int[items.length];
        for (int i = 0; i < items.length; i++) {
            target[i] = Integer.parseInt(items[i]);
        }
        return target;
    }

}
